package bs

import scala.xml.{Elem, NodeSeq}
import net.liftweb.http.Templates
import net.liftweb._
import http._
import util._
import Helpers._
import code.model.Member

case class HForm[T](inputs: (String, Elem)*) extends LiftComponent {
  val template: NodeSeq = Templates("templates-hidden" :: "bs" :: "_hform" :: Nil).get

  override def transformer: (NodeSeq) => NodeSeq = ".control-group" #> inputs.map { case (label, elem) =>
    val id = Option((elem \ "@id").text).filter(_.nonEmpty).getOrElse((math.random * 100).toInt.toString)

    ".control-label *" #> label &
      ".controls *" #> (elem % ("id" -> id)) &
      ".control-label [for]" #> id
  }
}
